/*
 * @Author: 张继伟
 * @Date: 2025-10-29 13:49:08
 * @Description: 
 */
import React, { ComponentType, lazy, Suspense } from 'react';
import { Spin } from 'antd';

// 高阶组件，用于包装懒加载组件
export function asyncComponent<T extends object>(
  importComponent: () => Promise<{ default: ComponentType<T> }>,
  fallback?: React.ReactNode
): React.ComponentType<T> {
  const LazyComponent = lazy(importComponent);

  return (props: T) => (
    <Suspense fallback={fallback || <Spin size="large" />}>
      <LazyComponent {...props} />
    </Suspense>
  );
}

// 预加载组件
export const preloadComponent = (importComponent: () => Promise<any>) => {
  return importComponent();
};